//数据库连接池配置
const mysql = require("mysql");
const connection = mysql.createConnection({
  host: process.env.DB_HOST, //ip地址
  user: process.env.DB_USER, //数据库用户名
  password: process.env.DB_PASS, //数据库用户密码
  port: process.env.DB_PORT, //数据库端口
  database: process.env.DB_DATATABLE, //数据库表名称
  multipleStatements: true, // 启用多语句支持
});
const pool = mysql.createPool({
  connectionLimit: 20, //最大连接数
  host: process.env.DB_HOST, //ip地址
  user: process.env.DB_USER, //数据库用户名
  password: process.env.DB_PASS, //数据库用户密码
  port: process.env.DB_PORT, //数据库端口
  database: process.env.DB_DATATABLE, //数据库表名称
  connectTimeout: 5000, //连接超时
  multipleStatements: true, // 启用多语句支持
});
const repool = () => {
  pool.on("connection", () => {
    console.log("数据库连接成功");
  });
};
module.exports = {
  connection,
  pool,
  repool,
};
